package com.jws.battleship;

import java.util.ArrayList;

public class Coordinate 
{
	public int x;
	public int y;
	
	public Coordinate()
	{
		x = 0;
		y = 0;
	}
	
	public Coordinate(String string)
	{		
		String[] values = string.split(",");
		
		x = Integer.parseInt(values[0]);
		y = Integer.parseInt(values[1]);
	}
	
	@Override
	public String toString() 
	{
		StringBuilder sb = new StringBuilder();
		
		sb.append(x);
		sb.append(',');
		sb.append(y);
		
		return sb.toString();
	}
	
	public static String coordinateListToString(ArrayList<Coordinate> list)
	{
		StringBuilder sb = new StringBuilder();
		
		for (Coordinate coordinate : list) 
		{			
			sb.append(coordinate.toString());
			sb.append(";");
		}
		
		sb.deleteCharAt(sb.length()-1);
		
		return sb.toString();
	}
	
	public static ArrayList<Coordinate> stringToCoordinateList(String string)
	{
		ArrayList<Coordinate> list = new ArrayList<Coordinate>();
		
		for (String coordinateString : string.split(";")) 
		{			
			list.add(new Coordinate(coordinateString));
		}
		
		return list;
	}
}
